<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        function Person(name) {
            this.name = name;
        }

        Person.prototype.sayHi = function () {
            console.log('这是原型对象上的说话方法');
        }

        var p1 = new Person('jack');
        p1.sayHi();


        p1.sayHi = function () {
            console.log('这是新的方法');
        }
        p1.sayHi();

        var p2 = new Person('andy');
        p2.sayHi();

    </script>
</body>

</html>